package com.moyu.user.utils;

import lombok.Data;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @Author 赵彦博
 * @Date 2025/3/25 22:05
 */
@Data
@Component
public class BuildAccountUtil {

    public String personId;

    public String init() {
        // 获取当前时间戳，精确到秒
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmm");
        String timestamp = sdf.format(new Date());
        // 生成 4 位随机数，范围是 1000 - 9999
        Random random = new Random();
        int randomNum = random.nextInt(9000) + 1000;

        // 拼接时间戳和随机数
        String combined = timestamp + randomNum;

        // 截取前 10 位
        personId = combined.substring(0, 10);

        return personId;
    }

}
